
/*
	1 - Entry of the page interaction after loding the words, the user must to add words for the filter
*/
function addFilterSocial(word){

	try{
		debug("Adding a new filter");
				
		page_results_filters[word]=word;
		
		var html="";
		
		for(word in page_results_filters){
			html+="<div class='filter' onclick=removeFilterSocial('"+word+"')>";
			html+=unescape(word)+"";
			html+="</div>";
		}
		
		var page_resultsfilter = $("#mediafilter");
		page_resultsfilter.html(html);
		
		showWait();
		searchpage_results();
		hideWait();
	}catch(e){
		error("addFilterSocial"+e.description);
	}
}

/*
	5 - Adding a new service to filter the results
*/
function addFilterService(service){

	try{
		
		debug("Adding a new service filter");
		
		services_filters[service]=service;
		
		var html="";
		
		for(service in services_filters){
		
			html+="<div class='filter' onclick=removeFilterService('"+service+"')>";
			html+=unescape(service)+"";
			html+="</div>";
		}
		
		var servicefilter = $("#servicefilter");
		servicefilter.html(html);

		showWait();
		searchServices();
		//hideWait();
	}catch(e){
		error("addFilterService"+e.description);
	}
}

/*
	2.5. - Filter the page_results with words
*/
function analizeContent(p_page){

	try{
			
		var positions=new Array();
		var position=0;
		
		//if one of the words is present, the pages is added
		for(word in page_results_filters){
		
			debug("Analize content "+unescape(word)+" for "+p_page.url);
			
			debug("Searching "+unescape(word));
			position=p_page.html.toUpperCase().search(unescape(word.toUpperCase()));
			if(position==-1){
				debug(unescape(word)+" not exists");
				return false;
			}else{
				debug(word+" is at "+position);
				
				positions[positions.length]=position;
			}
		}
		
		var result=getLink(p_page.html,position);
		
		return result;
	}catch(e){
		error("analizeContent"+e.description);
	}
}